
using System.Data.Common;
using MYLSOFT.JsonSimple;
using com.byt.webcore.utils.tree;
using System.Collections;

namespace com.byt.webcore.utils.ext
{

    public class Tree : com.byt.webcore.utils.tree.Tree
    {

        public Tree(DbDataReader rs)
            : base(rs, "children")
        {

        }

        protected Tree(DbDataReader rs, string nameNodeChilds)
        {
            JSONArray ja = Utils.getJSONArrayObject(rs);
            foreach (JSONObject jo in ja)
            {
                if (jo.ContainsKey("checked"))
                {
                    int? c = Utils.parseInteger(jo["checked"]);
                    jo.Remove("checked");
                    jo.Add("checked", (bool)(c == 1));
                }

                Node n = new Node(nameNodeChilds);
                foreach (DictionaryEntry it in jo)
                    n.Add(it.Key, it.Value);

                add(jo["id"] != null ? jo["id"].ToString() : null, n, jo["idsup"] != null ? jo["idsup"].ToString() : null);
            }
        }

    }
}